<template>
  <div id="map-container" class="map-container">
    <transition name="el-zoom-in-top">
      <div v-show="mapIframe" class="map-iframe">
        <div class="shenchaButton">
          <el-button @click="shenchaAct" type="primary" size="mini">审查意见</el-button>
          <el-button @click="guanbi" size="mini">关闭</el-button>
        </div>

        <div class="mapBox_left" style="width:100%;height:100%;">
          <span v-if="loadIfram == 1" class="iframeLoad">
            加载中
            <div class="el-icon-loading"></div>
          </span>
          <iframe
            v-if="loadIfram == 2"
            id="wode"
            :src="$httpsCad + '/?url=' + $https + xianZhuangPath"
            frameborder="0"
            name="iframeEle"
            style="width:100%;height:100%;"
          ></iframe>
        </div>
      </div>
    </transition>
    <l-map
      ref="map"
      class="map-right"
      style="height: 100%"
      :zoom="mapBaseConfig.zoom"
      :center="mapBaseConfig.center"
      :minZoom="mapBaseConfig.minZoom"
      :maxZoom="mapBaseConfig.maxZoom"
      :crs="mapBaseConfig.crs"
      :options="mapOptions"
    >
      <div v-show="isShowControls != false">
        <l-tile-layer v-if="mapMode == 'sl'" :url="mapLayers.cqVec.tileUrl"></l-tile-layer>
        <l-layer-group v-if="mapMode == 'yx'">
          <l-tile-layer :url="mapLayers.cqImg.tileUrl"></l-tile-layer>
          <l-tile-layer :url="mapLayers.cqMark.tileUrl"></l-tile-layer>
        </l-layer-group>
      </div>

      <!-- <l-layer-group v-if="sideBySideUrl.left != null && sideBySideUrl.right != null">
        <l-tile-layer ref="leftLayer" :url="sideBySideUrl.left"></l-tile-layer>
        <l-tile-layer ref="rightLayer" :url="sideBySideUrl.right"></l-tile-layer>
      </l-layer-group>-->

      <l-tile-layer v-for="(value, key, index) in treeCheckedObj" :key="key" :url="value.tileUrl"></l-tile-layer>

      <l-feature-group ref="features">
        <l-popup class="tdMap-popup-box" :options="{ minWidth: 760 }">
          <div class="piankuaiBox">
            <div class="piankuaihao">
              {{
              baseInfoData != null && baseInfoData != ""
              ? baseInfoData.pkh
              : "暂无数据"
              }}
            </div>
            <div class="piankuaiBox_select">
              <div
                @click="changeTab(1)"
                :class="{ piankuaiBox_select_item: true, active: tabFlag == 1 }"
              >基本信息</div>
              <div
                @click="changeTab(2)"
                :class="{ piankuaiBox_select_item: true, active: tabFlag == 2 }"
              >综合监管</div>
            </div>
            <div class="jibenxinxi" v-show="tabFlag == 1">
              <slot name="popupBaseInfo"></slot>
            </div>
            <div class="jibenxinxi" v-show="tabFlag == 2">
              <slot name="popupJgInfo"></slot>
            </div>
          </div>
        </l-popup>
      </l-feature-group>

      <l-geo-json
        @click="handleClickPolygon($event, item, index)"
        ref="geoJson"
        :optionsStyle="polygonStyleMap.defaultStyle"
        v-for="(item, index) in pkList"
        :key="index"
        :geojson="item.feature"
      ></l-geo-json>
    </l-map>

    <!-- 地图模式切换 s -->
    <div v-show="isShowControls != false" class="map-mode">
      <div @click.stop="changeMapMode('sl')" class="map-mode-item sl">
        <div class="text">矢量</div>
      </div>
      <div @click.stop="changeMapMode('yx')" class="map-mode-item yx">
        <div class="text">影像</div>
      </div>
    </div>
    <!-- 地图模式切换 e -->

    <!-- 地图工具栏 s -->
    <div v-show="isShowControls != false" class="map-tools">
      <div
        title="图层"
        :class="{ 'map-tools-item line': true, active: toolsValue.layer }"
        @click="handleToolsSwitch('layer')"
      >
        <svg-icon class="svg-icon" :icon-class="!toolsValue.layer ? 'chy-icon-nav' : 'chy-icon-nav-active'" />
        <!-- <i class="chy-icon-nav"></i> -->
      </div>

      <div
        id="lineMeasure"
        title="测距"
        :class="{ 'map-tools-item line': true, active: toolsValue.ruler }"
        @click="handleToolsSwitch('ruler')"
      >
        <svg-icon class="svg-icon" :icon-class="!toolsValue.ruler ? 'chy-icon-celiang' : 'chy-icon-celiang-active'" />
        <!-- <i class="chy-icon-celiang"></i> -->
      </div>

      <div
        id="areaMeasure"
        title="面积测量"
        :class="{ 'map-tools-item line': true, active: toolsValue.area }"
        @click="handleToolsSwitch('area')"
      >
        <svg-icon class="svg-icon" :icon-class="!toolsValue.area ? 'chy-icon-mianji' : 'chy-icon-mianji-active'" />
        <!-- <i class="chy-icon-mianji"></i> -->
      </div>

      <div
        title="卷帘对比"
        :class="{ 'map-tools-item line': true, active: toolsValue.cut }"
        @click="openSideBySidePopup"
      >
        <svg-icon class="svg-icon" :icon-class="!toolsValue.cut ? 'chy-icon-juanlian' : 'chy-icon-juanlian-active'" />
        <!-- <i class="chy-icon-juanlian"></i> -->
      </div>

      <div id="browserPrint" class="map-tools-item line" title="打印">
        <svg-icon class="svg-icon" icon-class="chy-icon-dayin" />
        <!-- <i class="chy-icon-dayin"></i> -->
      </div>

      <div
        :title="isFullScreen == true ? '退出全屏' : '全屏'"
        class="map-tools-item line"
        @click.stop="handleFullScreen"
      >
        <!-- <i :class="isFullScreen == true ? 'chy-icon-tuichuquanping' : 'chy-icon-quanping'"></i> -->
        <svg-icon class="svg-icon" icon-class="chy-icon-quanping" />
        <!-- <i class="chy-icon-quanping"></i> -->
      </div>

      <div class="map-tools-item line" title="清除测距、面积测量" @click.stop="handleClear">
        <svg-icon class="svg-icon" icon-class="chy-icon-qingchu" />
        <!-- <i class="chy-icon-qingchu"></i> -->
      </div>
    </div>
    <!-- 地图工具栏 e -->

    <!-- 地图图层 s -->
    <transition name="el-zoom-in-top">
      <div class="map-layer" v-show="toolsValue.layer">
        <el-collapse v-model="collapseValue">
          <el-collapse-item v-for="(item, index) in treeData" :key="index" name="1">
            <template slot="title">
              <div class="map-layer-title">{{ item.label }}</div>
            </template>
            <div class="map-layer-content">
              <div
                :class="{
                  'map-layer-content-item': true,
                  active: item2.isChecked
                }"
                @click="handleTreeCheck(item2)"
                v-for="(item2, index2) in item.children"
                :key="index2"
              >{{ item2.label }}</div>
            </div>
          </el-collapse-item>
        </el-collapse>
      </div>
    </transition>
    <!-- 地图图层 e -->

    <!-- 片块搜索区域 s -->
    <div v-show="isShowControls != false" class="map-search">
      <el-autocomplete
        @clear="handleAutocompleteClear"
        @select="handleMapSearchSelect"
        clearable
        class="map-search-input"
        v-model="searchValue"
        suffix-icon="el-icon-search"
        placeholder="搜索片块号"
        :fetch-suggestions="handlePkSearch"
      ></el-autocomplete>
      <el-button-group class="buttonGroupClass" v-show="currentPkData != null">
        <slot v-show="isShowXztBtn != false" name="buttonGroup"></slot>

        <el-dropdown @command="handleScView">
          <el-button class="line" size="medium">
            审查意见
            <i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="0" v-show="isShowScyjBtn != false">内业审查意见</el-dropdown-item>
            <el-dropdown-item command="1" v-show="isShowScWyBtn != false">外业审查意见</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-button-group>
    </div>
    <!-- 片块搜索区域 e -->

    <el-dialog :close-on-click-modal="false" :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" />
    </el-dialog>

    <el-dialog
      class="shenchaBoxDialog"
      :close-on-click-modal="false"
      title="审查意见"
      :visible.sync="xianZhuangShenCha"
    >
      <div class="shenchaBox">
        <div class="shenchaBox_mainBox">
          <div class="shenchaBox_item">
            <p>问题类型：</p>
            <div class="shenchaBox_item_input">
              <el-select
                @change="changeWenTi"
                class="shenchaBox_item_input"
                v-model="yijianObj.yijianValue"
                placeholder="--请选择--"
              >
                <el-option
                  v-for="item in cuowuList"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code"
                ></el-option>
              </el-select>
            </div>
          </div>
          <div class="shenchaBox_item" v-show="showWenTiBox">
            <p>问题内容：</p>
            <div class="shenchaBox_item_input">
              <el-input
                class="shenchaBox_item_input"
                type="textarea"
                :rows="4"
                placeholder="请输入内容"
                v-model="yijianObj.yijianContent"
              ></el-input>
            </div>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer" v-if="!isLook">
        <el-button @click="xianZhuangShenCha = false">取 消</el-button>
        <el-button
          type="primary"
          v-loading.fullscreen.lock="fullscreenLoading"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.6)"
          @click="submitXianZhuang"
        >提 交</el-button>
      </span>
    </el-dialog>

    <el-dialog
      class="side-by-side-popup"
      title="选择卷帘对比的图层"
      :close-on-click-modal="false"
      :visible.sync="sideBySidePopup"
    >
      <el-row :gutter="20">
        <el-col :span="12">
          <el-card header="左侧图层">
            <el-tree
              @node-click="handleSideBySideClick($event, 'left')"
              ref="leftTree"
              :data="treeData"
              :expand-on-click-node="false"
              :highlight-current="true"
              default-expand-all
              :props="defaultProps"
            ></el-tree>
          </el-card>
        </el-col>
        <el-col :span="12">
          <el-card header="右侧图层">
            <el-tree
              @node-click="handleSideBySideClick($event, 'right')"
              ref="rightTree"
              :data="treeData"
              :expand-on-click-node="false"
              :highlight-current="true"
              default-expand-all
              :props="defaultProps"
            ></el-tree>
          </el-card>
        </el-col>
      </el-row>
      <el-row>
        <el-button @click="handleSideBySide" class="confirm-btn">确定选择</el-button>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
// var L = require("@/lib/leaflet/leaflet");
import {
  LMap,
  LTileLayer,
  LPopup,
  LLayerGroup,
  LGeoJson,
  LFeatureGroup,
  LControl,
  LMarker
} from "vue2-leaflet";
import "leaflet/dist/leaflet.css";
import "@/icons/iconfont.css";
import "leaflet.browser.print/dist/leaflet.browser.print";

import icon from "leaflet/dist/images/marker-icon.png";
import iconShadow from "leaflet/dist/images/marker-shadow.png";
let DefaultIcon = L.icon({
  iconUrl: icon,
  shadowUrl: iconShadow
});
L.Marker.prototype.options.icon = DefaultIcon;

import "@/lib/leaflet/control.css";
import "@/lib/leaflet/control.js";

import { QScreenSwitcher } from "@/utils/common.js";

var esri = require("esri-leaflet");
import { getXctkDetail, getQqchDetail } from "@/api/tdMap";
import config from "@/config";

import "proj4leaflet/lib/proj4-compressed.js";
import "proj4leaflet/src/proj4leaflet.js";

export default {
  name: "tdMap",
  components: {
    LMap,
    LTileLayer,
    LPopup,
    LLayerGroup,
    LGeoJson,
    LFeatureGroup,
    LControl,
    LMarker
  },
  props: [
    "pkList",
    "isShowControls",
    "isShowScyjBtn",
    "isShowScWyBtn",
    "isShowXztBtn",
    "xianZhuangPath",
    "cuowuList",
    "yijianInfo",
    "isLook",
    "opinionType",
    "zhjgList"
  ],
  data() {
    return {
      //显示隐藏问题框
      showWenTiBox: true,
      yijianObj: {
        //意见类型
        yijianValue: "",
        //意见内容
        yijianContent: "",
        status: "" //状态
      },
      //审查现状图全屏加载
      fullscreenLoading: false,
      //审查现状图
      xianZhuangShenCha: false,
      //假装加载地图
      loadIfram: 2,
      //现状图显示关闭
      mapIframe: false,
      //显示四个输入框
      showThreeFlag: false,
      //是否为缺失遗漏点
      isMissingReclaimPoint: "NO",
      //审定规模与送审规模是否一致
      isIdenticalScale: "NO",
      //切换选项卡
      tabFlag: 1,
      // 地图图层模式
      mapMode: "yx", // yx影像；sl矢量
      // 地图弹层
      mapPopup: null,
      // 地图配置
      mapBaseConfig: {
        center: [29.57, 106.55],
        zoom: 10,
        minZoom: 0,
        maxZoom: 17,
        // zoom: 1,
        // minZoom: 0,
        // maxZoom: 10,

        crs: L.CRS.EPSG4326
      },
      mapCrs: new L.Proj.CRS(
        "EPSG:4490",
        "+proj=longlat +ellps=GRS80 +no_defs ",
        {
          resolutions: [
            0.00951784402332112,
            0.006662490816324785,
            0.00237946100583028,
            0.00118973050291514,
            5.9486525145757e-4,
            2.3794610058302802e-4,
            1.1897305029151401e-4,
            5.9486525145757005e-5,
            2.3794610058302804e-5,
            1.1897305029151402e-5,
            4.75892201166056e-6
          ],
          origin: [-400.0, 399.9999999999998]
        }
      ),
      mapOptions: {
        zoomControl: false
      },
      // 地图图层
      mapLayers: {
        // 矢量
        cqVec: esri.tiledMapLayer({
          url:
            "http://www.digitalcq.com/tianditu/hlvdl/765c64c33a9d4beeae5c5329da6caebf"
        }),
        // 影像
        cqImg: esri.tiledMapLayer({
          url:
            // "http://www.digitalcq.com/tianditu/kxrgo/ca295a0983c5473a825b1e4700adb81b"
            // 'http://10.10.6.7:8000/tcloud/rest/services/YGYX2016_2000/MapServer?access_token=AT-41-VFSwcRcqwB-rDTSL-xLLbASLZ84Axz1D'
            'http://222.178.223.250:2136/arcgis/rest/services/tdzz/CQ_img/MapServer'
        }),
        // 影像注记
        cqMark: esri.tiledMapLayer({
          url:
            "http://www.digitalcq.com/tianditu/ewfwz/ff74349b1483497d913ec396ee35065b"
        })
      },
      // geoJson style
      polygonStyleMap: {
        defaultStyle: {
          color: "#ff0000",
          weight: 1,
          fillOpacity: 0.2
        },
        activeStyle: {
          // color: "#ff6600",
          color: "#ff6600",
          weight: 2,
          fillOpacity: 0.2
        }
      },

      // 地图导航配置
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 地图导航数据
      treeData: [
        {
          id: 1,
          label: "土地利用规划",
          disabled: true,
          children: [
            {
              id: 5,
              label: "总体规划",
              disabled: true,
              isChecked: false
            },
            {
              id: 6,
              label: "管理区规划",
              disabled: true,
              isChecked: false
            },
            {
              id: 7,
              label: "土地整治规划",
              disabled: true,
              isChecked: false
            }
          ]
        },
        {
          id: 2,
          label: "城市规划",
          disabled: true,
          children: [
            {
              id: 16,
              label: "用地规划",
              disabled: true,
              isChecked: false
            },
            {
              id: 17,
              label: "控规用地规划",
              disabled: true,
              isChecked: false
            },
            {
              id: 18,
              label: "总规深化用地规划",
              disabled: true,
              isChecked: false
            }
          ]
        },
        {
          id: 3,
          label: "土地利用现状",
          children: [
            {
              id: 8,
              label: "2018年",
              // url: esri.tiledMapLayer({
              //   url:
              //     "http://10.10.6.7:8000/tcloud/rest/services/2018tdlyxz_2000/MapServer?access_token=AT-41-VFSwcRcqwB-rDTSL-xLLbASLZ84Axz1D"
              // }),
              url: esri.tiledMapLayer({
                url:
                  "http://222.178.223.250:2136/arcgis/rest/services/tdzz/tdlyxz_3/MapServer"
              }),
              isChecked: false
            },
            {
              id: 9,
              label: "2017年",
              // disabled: true,
              url: esri.tiledMapLayer({
                url:
                  "http://222.178.223.250:2136/arcgis/rest/services/tdzz/LXZ_tdly/MapServer"
              }),
              isChecked: false
            },
            {
              id: 10,
              label: "2016年",
              disabled: true,
              isChecked: false
            },
            {
              id: 11,
              label: "2015年",
              disabled: true,
              isChecked: false
            }
          ]
        },
        {
          id: 4,
          label: "年度变更影像",
          children: [
            {
              id: 12,
              label: "2018年",
              // disabled: true,
              url: esri.tiledMapLayer({
                url:
                  "http://222.178.223.250:2136/arcgis/rest/services/tdzz/LXZ_img/MapServer"
                  // 'http://10.10.6.7:8000/tcloud/rest/services/CQYX2018_2000/MapServer?access_token=AT-41-VFSwcRcqwB-rDTSL-xLLbASLZ84Axz1D'
              }),
              isChecked: false
            },
            {
              id: 13,
              label: "2017年",
              url: esri.tiledMapLayer({
                url:
                  "http://www.digitalcq.com/tianditu/dsrqc/c54e73a8bdd441b495ee531110f8086b"
              }),
              isChecked: false
            },
            {
              id: 14,
              label: "2016年",
              url: esri.tiledMapLayer({
                url:
                  "http://www.digitalcq.com/tianditu/pzosy/a0abcb4bb7db466e973cbd8867b47fe6"
              }),
              isChecked: false
            },
            {
              id: 15,
              label: "2015年",
              url: esri.tiledMapLayer({
                url:
                  "http://www.digitalcq.com/tianditu/hrjvz/6691ab289e6745feaa6580c630afe945"
              }),
              isChecked: false
            }
          ]
        }
      ],

      // 页面参数
      navActive: true,
      polygonArr: [],
      polygonMap: {},
      geoJsonArr: [],
      geoJsonOptions: {},
      popupActiveName: "baseInfo",
      baseInfoData: null, // 基本信息数据
      jgInfoData: {
        //监管信息数据
        xctk: null, // 现场踏勘
        xctkList: [],
        qqch: null, // 前期测绘
        qqchList: [],
        cgcs: null // 成果初审
      },
      jgInfoTabActiveName: "xctk",
      jgInfoLoading: false,
      dialogVisible: false,
      dialogImageUrl: null,
      treeCheckedObj: {},
      control: {
        lineMeasure: null,
        areaMeasure: null,
        browserPrint: null,
        siderCompare: null
      },
      fullScreen: new QScreenSwitcher(),
      isFullScreen: false,

      isFalse: true,
      sideBySidePopup: false, //卷帘对比选择弹窗
      sideBySideStatus: "close",
      sideBySideUrl: {
        left: null,
        right: null
      },
      markerLatLng: null,
      searchValue: "", // 搜索值
      collapseValue: "1", // 折叠面板
      toolsValue: {
        // 地图工具开关状态
        layer: false,
        ruler: false,
        area: false,
        cut: false
      },
      currentPolygon: null,
      currentPkData: null // 当前选中片块
    };
  },
  watch: {
    pkList() {
      // 监听片块列表变化
      this.pkList.forEach((item, index) => {
        item["value"] = item.pkh || item.pkm || item.landName;
        item["index"] = index;
      });
      this.initMap();
    },
    baseInfoData() {
      this.getXctkData();
      this.getQqchData();
    },
    // xianZhuangPath(val) {
    //   var that = this;
    //   if (this.xianZhuangPath) {

    //   } else {
    //     this.mapIframe = false;
    //   }
    // },
    yijianInfo() {
      //意见回显
      // this.yijianObj.yijianValue=this.yijianInfo.yijianTyPe
      // this.yijianObj.yijianContent=this.yijianInfo.yijianContent
      // if (this.yijianObj.yijianValue == "NO_PROBLEM") {
      //   this.showWenTiBox = false;
      // } else {
      //   this.showWenTiBox = true;
      // }
    }
    // opinionType(){

    //   let that=this
    //   this.$nextTick(()=>{
    //     that.yijianObj.yijianValue=that.opinionType

    //   })

    // }
    // popupActiveName(val) {
    //   if (val == "jgInfo") {
    //     this.getXctkData();
    //   }
    // },
    // jgInfoTabActiveName(val) {
    //   if (val == "xctk") {
    //     this.getXctkData();
    //   } else if (val == "qqch") {
    //     this.getQqchData();
    //   }
    // }
  },
  methods: {
    //关闭显示现状图的iframe
    closeMapIframe() {
      // this.loadIfram = 1;
      this.mapIframe = false;
    },
    //关闭弹框
    closeXianZhuang() {
      this.xianZhuangShenCha = false;
      this.fullscreenLoading = false;
      this.yijianObj.yijianValue = "";
      this.yijianObj.yijianContent = "";
    },
    //选择问题类型(用于无问题时隐藏输入意见框)
    changeWenTi(v) {
      if (v == "NO_PROBLEM") {
        this.showWenTiBox = false;
      } else {
        this.showWenTiBox = true;
      }
    },
    //审查现状图弹框
    shenchaAct() {
      if (this.yijianInfo.status == "VIEW") {
        this.yijianObj.yijianValue = this.yijianInfo.yijianValue;
        this.yijianObj.yijianContent = this.yijianInfo.yijianContent;
        if (this.yijianObj.yijianValue == "NO_PROBLEM") {
          this.showWenTiBox = false;
        } else {
          this.showWenTiBox = true;
        }
      } else if (this.yijianInfo.status == "AUDIT") {
        this.yijianObj.yijianValue = "";
        this.yijianObj.yijianContent = "";
      }
      this.xianZhuangShenCha = true;
    },
    //提交现状
    submitXianZhuang() {
      var obj = {
        landId: this.currentPkData.landId,
        yijianValue: this.yijianObj.yijianValue,
        yijianContent: this.yijianObj.yijianContent
      };
      this.fullscreenLoading = true;
      this.$parent.wentijilu(obj);
    },
    //关闭现状图
    guanbi() {
      this.$parent.guanbiXianZhuang();
      this.mapIframe = false;
      // this.loadIfram = 1;
    },
    //切换单选
    isShowThreeInput(e) {
      if (e == "NO") {
        this.showThreeFlag = true;
      } else {
        this.showThreeFlag = false;
      }
    },
    //切换选项卡
    changeTab(num) {
      this.tabFlag = num;
    },
    handleFullScreen() {
      // 全屏
      if (this.isFullScreen) {
        this.fullScreen.exitFullScreen(
          document.getElementById("map-container")
        );
      } else {
        this.fullScreen.enterFullScreen(
          document.getElementById("map-container")
        );
      }
      // if (this.isFullScreen) {
      //   this.fullScreen.exitFullScreen(this.$refs.map.$el);
      // } else {
      //   this.fullScreen.enterFullScreen(this.$refs.map.$el);
      // }
      this.isFullScreen = !this.isFullScreen;
    },
    handleClear() {
      // 清除测距、面积测距
      let _lineMeasureLayer = this.control["lineMeasure"]["_layerPaint"];
      let _areaMeasureLayer = this.control["areaMeasure"]["_layer"];
      if (_areaMeasureLayer != null) {
        for (var k in _areaMeasureLayer["_layers"]) {
          _areaMeasureLayer.removeLayer(_areaMeasureLayer["_layers"][k]);
        }
      }
      if (_lineMeasureLayer != null) {
        _lineMeasureLayer.clearLayers();
      }

      this.toolsValue["ruler"] = false;
      this.toolsValue["area"] = false;
    },
    openSideBySidePopup() {
      if (this.sideBySideStatus == "close") {
        this.sideBySidePopup = true;
      } else {
        this.handleToolsSwitch("cut");
        this.$refs.map.mapObject.removeLayer(this.sideBySideUrl.left);
        this.$refs.map.mapObject.removeLayer(this.sideBySideUrl.right);
        this.control.siderCompare.remove();
        this.sideBySideStatus = "close";
      }
    },
    handleSideBySideClick(e, name) {
      if (e.url) {
        this.sideBySideUrl[name] = e.url;
      } else {
        this.sideBySideUrl[name] = null;
        this.$message({
          message: `${name == "left" ? "左侧" : "右侧"}所选图层暂无数据`,
          type: "warning"
        });
      }
    },
    handleSideBySide() {
      // 卷帘对比
      if (this.sideBySideUrl.left == null) {
        this.$message({
          message: `左侧所选图层暂无数据`,
          type: "warning"
        });
        return;
      }
      if (this.sideBySideUrl.right == null) {
        this.$message({
          message: `右侧所选图层暂无数据`,
          type: "warning"
        });
        return;
      }
      let left = this.sideBySideUrl.left;
      let right = this.sideBySideUrl.right;
      this.$refs.map.mapObject.addLayer(left);
      this.$refs.map.mapObject.addLayer(right);
      this.control.siderCompare = L.control
        .sideBySide(left, right)
        .addTo(this.$refs.map.mapObject);
      this.sideBySidePopup = false;
      this.sideBySideStatus = "open";
      this.handleToolsSwitch("cut");
    },
    initMap() {
      this.$nextTick(() => {
        let _geoJsonArr = [];
        this.$refs.geoJson.forEach((item, index) => {
          _geoJsonArr.push(item.getBounds());
        });
        this.geoJsonArr = _geoJsonArr;
        this.$refs.map.fitBounds(this.geoJsonArr); // 定位到图形位置

        if (
          this.isShowControls == false &&
          this.zhjgList &&
          this.zhjgList.length > 0
        ) {
          this.zhjgList.forEach(item => {
            if (item.coorDonate) {
              let arr = item.coorDonate.split(",");
              L.marker([arr[1], arr[0]]).addTo(this.$refs.map.mapObject);
            }
          });
        }

        // 加载测距、面积测距、打印控件
        this.control.lineMeasure = L.control
          .lineMeasure({ drawBtn: document.getElementById("lineMeasure") })
          .addTo(this.$refs.map.mapObject);
        this.control.areaMeasure = L.control
          .areaMeasure({ drawBtn: document.getElementById("areaMeasure") })
          .addTo(this.$refs.map.mapObject);
        this.control.browserPrint = L.control
          .browserPrint({ el: document.getElementById("browserPrint") })
          .addTo(this.$refs.map.mapObject);
      });
    },
    changeMapMode(mode) {
      // 切换地图模式
      this.mapMode = mode;
    },
    handleClickPolygon(e, item, index) {
      // 点击多边形开启片块详情popup
      this.$parent.getCurListIndex(index);
      this.baseInfoData = item;
      this.$nextTick(() => {
        this.$refs.features.mapObject.openPopup([e.latlng.lat, e.latlng.lng]);
      });
    },
    changePkPosition(index) {
      // 点击
      this.restorePolygonStyle();
      this.currentPolygon = this.$refs.geoJson[index];
      this.currentPolygon.setOptionsStyle(this.polygonStyleMap.activeStyle);
      this.$refs.map.fitBounds(this.currentPolygon.getBounds());
    },
    restorePolygonStyle() {
      // 重置地图片块样式
      this.$refs.geoJson.forEach((item, index) => {
        item.setOptionsStyle(this.polygonStyleMap.defaultStyle);
      });
    },
    getXctkData() {
      // 获取现场踏勘数据
      this.jgInfoLoading = true;
      getXctkDetail({
        landId: this.baseInfoData.landId
      })
        .then(res => {
          this.jgInfoLoading = false;
          this.jgInfoData.xctk = res.data;
          this.jgInfoData.xctkList = [
            { name: "情况说明照片1", src: config.baseUrl + res.data.photo1 },
            { name: "情况说明照片2", src: config.baseUrl + res.data.photo1 }
          ];
        })
        .catch(err => {
          this.jgInfoLoading = false;
        });
    },
    getQqchData() {
      // 获取前期测绘数据
      this.jgInfoLoading = true;
      getQqchDetail({
        landId: this.baseInfoData.landId
      })
        .then(res => {
          this.jgInfoLoading = false;
          this.jgInfoData.qqch = res.data;
          this.jgInfoData.qqchList = [
            {
              name: "空中全景照片",
              src: config.baseUrl + res.data.panoramagramFilePath
            },
            {
              name: "复垦点方位一照片",
              src: config.baseUrl + res.data.landPositionOneFilePath
            },
            {
              name: "复垦点方位二照片",
              src: config.baseUrl + res.data.landPositionTwoFilePath
            },
            {
              name: "复垦点方位三照片",
              src: config.baseUrl + res.data.landPositionThreeFilePath
            },
            {
              name: "复垦点方位四照片",
              src: config.baseUrl + res.data.landPositionFourFilePath
            }
          ];
        })
        .catch(err => {
          this.jgInfoLoading = false;
        });
    },
    handleImageDialog(url) {
      this.dialogImageUrl = url;
      this.dialogVisible = true;
    },
    handleTreeCheck(item) {
      if (item.disabled) {
        this.$message({
          message: `暂无图层`,
          type: "warning"
        });
        return;
      }
      if (item.url) {
        item.isChecked = !item.isChecked;
        if (item.isChecked == true) {
          this.treeCheckedObj[item.id] = item.url;
        } else {
          delete this.treeCheckedObj[item.id];
        }
      }
      this.$forceUpdate();
    },
    handlePkSearch(queryString, callback) {
      var restaurants = this.pkList;
      var results = queryString
        ? restaurants.filter(this.createFilter(queryString))
        : restaurants;
      callback(results);
    },
    createFilter(queryString) {
      return restaurant => {
        return (
          restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) ===
          0
        );
      };
    },

    handleMapSearchSelect(item) {
      this.currentPkData = item;
      this.changePkPosition(item.index);
    },
    handleToolsSwitch(name) {
      this.toolsValue[name] = !this.toolsValue[name];
    },
    handleXzView() {
      this.mapIframe = true;
      // console.log(window.frames['iframeEle'].document.getElementById('CADControl1'))
      this.$parent.toSeeXianZhuang(this.currentPkData);
    },
    handleAutocompleteClear() {
      this.restorePolygonStyle();
      this.currentPkData = null;
      this.$refs.map.fitBounds(this.geoJsonArr); // 定位到图形位置
    },
    handleScView(value) {
      if (value == 0) {
        this.$parent.shenchaYj(this.currentPkData);
        return;
      }
      if (value == 1) {
        this.$parent.shenchaWy(this.currentPkData);
      }
    }
  },
  created() {
    // if (!this.isShowControls) {
    //   this.isShowControls = true;
    // }
  }
};
</script>

<style lang="scss" scoped>
.map-container {
  position: relative;
  display: flex;
  justify-content: center;
  // height: calc(100vh - 200px);
  height: 100%;
  // margin-top: 30px;
  // margin-bottom: 30px;
}
.map-left {
  width: 0;
  border: 1px solid #e9e9e9;
  border-right: none;

  &.active {
    width: 230px;
  }
}
.map-nav {
  background: #f2f2f2;
  height: 40px;
  border-bottom: 1px solid #e9e9e9;
  overflow: hidden;
  text-align: center;
  font-size: 16px;
  font-weight: bold;
  color: #4d4d4d;
  line-height: 40px;
}
.map-right {
  width: 100%;
}
.map-mode {
  display: flex;
  flex-direction: row;
  width: auto;
  height: 62px;
  overflow: hidden;
  font-size: 0;
  position: absolute;
  z-index: 500;
  right: 0;
  bottom: 30px;

  &-item {
    position: relative;
    width: 62px;
    height: 62px;
    display: block;
    overflow: hidden;
    border: 1px solid #308be7;
    margin-right: 10px;
    cursor: pointer;

    .text {
      background: rgba(0, 0, 0, 0.5);
      width: 100%;
      height: 20px;
      display: block;
      overflow: hidden;
      font-size: 13px;
      color: #fff;
      text-align: center;
      line-height: 20px;
      position: absolute;
      left: 0;
      bottom: 0;
      z-index: 1;
    }
  }

  &-item.yx {
    background: url("../../assets/map/type-img-icon.png");
    background-repeat: no-repeat;
    background-size: cover;
  }

  &-item.sl {
    background: url("../../assets/map/type-vector-icon.png");
    background-repeat: no-repeat;
    background-size: cover;
  }
}

.nav-switch {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  background: #fff;
  width: 20px;
  height: 30px;
  border: 1px solid #ccc;
  border-left: 0 none;
  display: block;
  overflow: hidden;
  font-size: 18px;
  text-align: center;
  line-height: 30px;
  position: absolute;
  z-index: 1001;
  border-radius: 0 5px 5px 0;
  cursor: pointer;
}

.map-tools {
  width: auto;
  height: 40px;
  border-radius: 4px;
  box-shadow: 1px 1px 2px #666;
  overflow: hidden;
  font-size: 0;
  position: absolute;
  z-index: 500;
  right: 30px;
  top: 30px;
  cursor: pointer;

  &-item {
    position: relative;
    float: left;
    background: #fff;
    // width: 40px;
    padding: 0 12px;
    // border-bottom: 1px solid #efefef;
    overflow: hidden;
    line-height: 40px;
    font-size: 0;
    color: #666;
    text-align: center;
    // border-right: 1px solid #e6e6e6;

    &.line:after {
      position: absolute;
      display: block;
      content: "";
      top: 50%;
      transform: translateY(-50%);
      left: 0;
      width: 1px;
      height: 18px;
      background: rgba(230, 230, 230, 1);
    }

    i {
      color: #666;
      display: block;
    }

    .svg-icon {
      display: block;
      font-size: 24px;
      height: 40px;
      color: #666;
    }

    &.active {
      i {
        color: #409eff;
      }
    }

    &:hover {
      background: #efefef;
    }
  }
}

.map-search {
  position: absolute;
  z-index: 500;
  left: 30px;
  top: 30px;
  font-size: 0;
  display: flex;
  flex-direction: row;

  .line:after {
    position: absolute;
    display: block;
    content: "";
    top: 50%;
    transform: translateY(-50%);
    left: 0;
    width: 1px;
    height: 18px;
    background: rgba(230, 230, 230, 1);
  }

  /deep/ .el-button-group {
    position: relative;
    margin-left: 10px;
    border-radius: 4px;
    box-shadow: 1px 1px 2px #666;
  }

  /deep/ .el-button {
    border: 1px solid #fff;
  }

  /deep/ .el-input__inner {
    width: 344px;
    border-radius: 4px;
    box-shadow: 1px 1px 2px #666;
  }

  /deep/ .el-input__inner {
    height: 36px;
    border: none;
  }

  /deep/ .el-input__icon {
    font-size: 18px;
    line-height: 36px;
    color: #999;
  }

  ::-webkit-input-placeholder {
    /* WebKit browsers */
    color: #b3b3b3;
    font-size: 14px;
  }

  ::-moz-placeholder {
    /* Mozilla Firefox 19+ */
    color: #b3b3b3;
    font-size: 14px;
  }

  :-ms-input-placeholder {
    /* Internet Explorer 10+ */
    color: #b3b3b3;
    font-size: 14px;
  }
}

.map-layer {
  width: 392px;
  position: absolute;
  z-index: 1001;
  right: 30px;
  top: 86px;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 1px 1px 2px #666;

  /deep/ .el-collapse-item__header {
    // background-color: #f5f5f5;
    height: 40px;
    line-height: 40px;
    box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.2);
  }

  /deep/ .el-collapse-item__wrap {
    background-color: rgba(255, 255, 255, 0.8);
  }

  /deep/ .el-collapse-item__arrow {
    margin: 0 18px 0 auto;
  }

  &-title {
    position: relative;
    font-size: 16px;
    font-family: PingFang SC;
    font-weight: 500;
    color: rgba(77, 77, 77, 1);
    margin-left: 28px;

    &::before {
      content: "";
      position: absolute;
      display: block;
      width: 3px;
      height: 16px;
      background: rgba(21, 112, 213, 1);
      top: 50%;
      left: -8px;
      transform: translateY(-50%);
    }
  }

  /deep/ .el-collapse-item__content {
    padding-bottom: 0;
  }

  &-content {
    display: flex;
    flex-wrap: wrap;
    padding: 20px;

    &-item {
      font-size: 15px;
      font-family: PingFang SC;
      font-weight: 500;
      color: rgba(102, 102, 102, 1);
      margin-right: 24px;
      transition: all 0.3s;
      cursor: pointer;

      &:hover {
        color: #409eff;
      }

      &.active {
        color: #409eff;
      }
    }
  }
}

.leaflet-control-browser-print {
  display: none;
}

.side-by-side-popup {
  text-align: center;

  .confirm-btn {
    margin-top: 26px;
  }

  /deep/
    .el-tree--highlight-current
    .el-tree-node.is-current
    > .el-tree-node__content {
    // background-color: #f9b5a3;
    background-color: rgb(160, 207, 255);
  }
}

.piankuaiBox_select {
  display: flex;
  margin: 28px 0;

  .piankuaiBox_select_item {
    width: 88px;
    height: 36px;
    background: #fff;
    opacity: 1;
    border-radius: 4px;
    color: #999999;
    text-align: center;
    line-height: 36px;
    font-size: 14px;
    margin-right: 8px;
    cursor: pointer;
  }

  .piankuaiBox_select_item.active {
    background: rgba(238, 243, 248, 1);
    color: #1d88f3;
  }
}

.piankuaihao {
  font-size: 20px;
  line-height: 28px;
  padding-bottom: 20px;
  color: #333333;
  border-bottom: 1px solid #f2f2f2;
}

.jibenxinxi {
  height: 300px;
  overflow-x: hidden;
  overflow-y: auto;

  ul {
    list-style: none;
    overflow: hidden;
    padding-left: 10px;
    margin-top: 30px;

    li {
      float: left;
      color: #b3b3b3;
      font-size: 13px;
      margin-right: 40px;
      margin-bottom: 16px;

      span {
        color: #666666;
      }

      .redText {
        color: red;
      }
    }
  }
}

.jibenxinxi .ziliaoList {
  overflow: hidden;
  margin-top: 0;
  padding-left: 0;

  li {
    float: left;
    font-size: 14px;
    color: #1d88f3;
    margin-left: 18px;
    margin-right: 0;
    cursor: pointer;
  }
}

.yijianBox-item {
  margin-bottom: 20px;
  font-size: 14px;
  color: #666666;
  display: flex;

  .yijianBox-item-left {
    margin-right: 30px;
  }
}

.jibenxinxiyijian {
  margin-top: 33px;
  margin-left: 10px;
}

.submityijian {
  margin-top: 60px;
}

.iframeLoad {
  display: flex;
  font-size: 35px;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
}

.map-iframe {
  opacity: 0.5;
  position: absolute;
  top: 0;
  right: 0;
  z-index: 501;
  width: 50%;
  height: 100%;
  box-sizing: border-box;
  padding-top: 40px;
  background-color: #fff;

  .shenchaButton {
    position: absolute;
    top: 10px;
    right: 10px;
  }
}

.map-iframe:hover {
  opacity: 1;
}

.shenchaBox {
  margin-top: 20px;
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.shenchaBox_item_input {
  width: 300px;
}

.shenchaBox_item_button {
  width: 300px;
  display: flex;
  justify-content: center;
  margin-top: 20px;
  margin-bottom: 50px;
}

.shenchaBoxDialog /deep/ .el-dialog {
  width: 500px;
}

.buttonGroupClass {
  display: flex;
}

/deep/ .leaflet-popup-content {
  margin: 0;
  padding: 30px;
}
</style>
